clear

set scheme plotplain

use Data_Proc\recs_clean

gen new = recs2020
keep if recs==2020 | recs==2009
keep if heat==1



***********************************************
* GENERATE AND LABEL VARIABLES FOR REGRESSIONS 
***********************************************

* CENSUS DIVISIONS
local divisions "EastNorthCentral EastSouthCentral MiddleAtlantic MountainNorth MountainSouth NewEngland Pacific SouthAtlantic WestNorthCentral WestSouthCentral"
foreach d of local divisions  {
	gen div_`d' = (div=="`d'")
	gen new_div_`d' = new*div_`d'
	la var new_div_`d' "`d'"
	la var div_`d' "`d'"
}
drop new_div_EastNorthCentral div_EastNorthCentral

* CENSUS REGIONS
local regions "Northeast Midwest South West"
foreach r of local regions  {
	gen reg_`r' = (region=="`r'")
	gen new_reg_`r' = new*reg_`r'
	la var new_reg_`r' "`r'"
	la var reg_`r' "`r'"
}
drop new_reg_Midwest reg_Midwest

* RURAL
gen new_rural = new*rural
la var new_rural "Rural"
la var rural "Rural"

* OWNER
gen new_own = new*own
la var new_own "Owner"
la var own "Owner"

* INCOME
forvalues i = 2/4 {
	gen inc_`i' = (incomeq==`i')
	gen new_inc_`i' = new*inc_`i'
}
la var new_inc_2 "$30-59k"
la var new_inc_3 "$60-99k"
la var new_inc_4 "$100k+"
la var inc_2 "$30-59k"
la var inc_3 "$60-99k"
la var inc_4 "$100k+"

* RACE
local races "black native asian other"
foreach r of local races {
	gen rac_`r' = `r'
	gen new_rac_`r' = new*rac_`r'
}
la var rac_black "Black"
la var rac_native "Nat.Am."
la var rac_asian "Asian"
la var rac_other "Other"
la var new_rac_black "Black"
la var new_rac_native "Nat.Am."
la var new_rac_asian "Asian"
la var new_rac_other "Other"

* VINTAGE
forvalues t = 1950(10)2000 {
	gen vin_`t' = (vintage==`t')
	gen new_vin_`t' = new*vin_`t'
	la var new_vin_`t' "`t's"
	la var vin_`t' "`t's"
}

* RENAME FUEL COSTS
ren lnce lncelec
ren lnch lnchp
ren lncg lncngas
ren lnco lnckero
ren lncp lncprop


* GENERATE HP AND OTHER FUEL COST NAMES
la var lnca "ln(other cost)"
la var lnchp "ln(hp cost)"
gen new_lnchp = new*lnchp
la var new_lnchp "ln(hp cost)"
gen new_lncr = new*lncr
la var lncr "ln(other cost) - ln(hp cost)"
la var new_lncr "ln(other cost) - ln(hp cost)"


* GENERATE GENERIC FUEL COST NAMES FOR LOOPING OVER DIFFERENT FUEL TYPES
gen lncfuel = 0
gen new_lncfuel = 0
la var lncfuel "ln(other cost)"
la var new_lncfuel "ln(other cost)"
gen lncself = 0
gen new_lncself = 0
la var lncself "ln(col. cost)"
la var new_lncself "ln(col. cost)"
gen lncfuelself = 0
gen new_lncfuelself = 0
la var lncfuelself "ln(other cost) - ln(col. cost)"
la var new_lncfuelself "ln(other cost) - ln(col. cost)"


***********************************************
* BUILD REGRESSION TABLES
***********************************************

* OLD HOMES: CORRELATES OF HEAT PUMP CONVERSIONS
eststo clear
eststo: reg hp new lncr new_lncr						if vintage<=2000 [pw=nweight], robust
eststo: reg hp new inc_* new_inc_*						if vintage<=2000 [pw=nweight], robust
eststo: reg hp new rac_* new_rac_*						if vintage<=2000 [pw=nweight], robust
eststo: reg hp new own new_own							if vintage<=2000 [pw=nweight], robust
eststo: reg hp new rural new_rural						if vintage<=2000 [pw=nweight], robust
eststo: reg hp new reg_* new_reg_*						if vintage<=2000 [pw=nweight], robust
eststo: reg hp new vin_* new_vin_* 						if vintage<=2000 [pw=nweight], robust
eststo: reg hp new lncr new_lncr inc_* new_inc_* rac_* new_rac_* own new_own rural new_rural reg_* new_reg_* vin_* new_vin_* ///
														if vintage<=2000 [pw=nweight], robust
esttab using Final_Output\tab_OldHeatPumpRegs_Update.tex, label replace order(new_lncr new_inc_* new_rac_* new_own new_rural new_reg_* new_vin_*) keep(new_lncr new_inc_* new_rac_* new_own new_rural new_reg_* new_vin_*) noconstant b(3) se(3) fragment nomtitles substitute($ "\\$")


* OLD HOMES: CORRELATES OF HEAT PUMP CONVERSIONS (NO COVID)
eststo clear
eststo: reg hp new lncr new_lncr						if vintage<=2000 & age>0 [pw=nweight], robust
eststo: reg hp new inc_* new_inc_*						if vintage<=2000 & age>0 [pw=nweight], robust
eststo: reg hp new rac_* new_rac_*						if vintage<=2000 & age>0 [pw=nweight], robust
eststo: reg hp new own new_own							if vintage<=2000 & age>0 [pw=nweight], robust
eststo: reg hp new rural new_rural						if vintage<=2000 & age>0 [pw=nweight], robust
eststo: reg hp new reg_* new_reg_*						if vintage<=2000 & age>0 [pw=nweight], robust
eststo: reg hp new vin_* new_vin_* 						if vintage<=2000 & age>0 [pw=nweight], robust
eststo: reg hp new lncr new_lncr inc_* new_inc_* rac_* new_rac_* own new_own rural new_rural reg_* new_reg_* vin_* new_vin_* ///
														if vintage<=2000 & age>0 [pw=nweight], robust
esttab using Final_Output\tab_OldHeatPumpRegs_NoCovid_Update.tex, label replace order(new_lncr new_inc_* new_rac_* new_own new_rural new_reg_* new_vin_*) keep(new_lncr new_inc_* new_rac_* new_own new_rural new_reg_* new_vin_*) noconstant b(3) se(3) fragment nomtitles substitute($ "\\$")


* NEW HOMES: CORRELATES OF HEAT PUMP SHARES
eststo clear
eststo: reg hp lncr 								if vintage>2000 [pw=nweight], robust
eststo: reg hp inc_*								if vintage>2000 [pw=nweight], robust
eststo: reg hp rac_*								if vintage>2000 [pw=nweight], robust
eststo: reg hp own									if vintage>2000 [pw=nweight], robust
eststo: reg hp rural								if vintage>2000 [pw=nweight], robust
eststo: reg hp reg_*								if vintage>2000 [pw=nweight], robust
eststo: reg hp lncr inc_* rac_* own rural reg_*		if vintage>2000 [pw=nweight], robust
esttab using Final_Output\tab_NewHeatPumpRegs_Update.tex, label replace order(lncr inc_* rac_* own rural reg_*) keep(lncr inc_* rac_* own rural reg_*) noconstant b(3) se(3) fragment nomtitles substitute($ "\\$")


* OLD HOMES: CORRELATES OF HEATING FUEL CONVERSIONS
eststo clear
local heatlist "hp elec ngas kero prop"
foreach h of local heatlist { 
	replace lncself = lnc`h'
	replace lncfuel = (lnca*(shp + selec + sngas + skero + sprop) - s`h'*lnc`h')/(shp + selec + sngas + skero + sprop - s`h')
	replace lncfuelself = lncfuel - lncself
	replace new_lncfuelself = new*lncfuelself
	eststo: reg `h' new if vintage<=2000 [pw=nweight], robust
	estimates store simpreg_`h'
	eststo: reg `h' new lncfuelself new_lncfuelself inc_* new_inc_* rac_* new_rac_* own new_own rural new_rural reg_* new_reg_* vin_* new_vin_* if vintage<=2000 [pw=nweight], robust
	estimates store reg_`h'
}
esttab reg_hp reg_elec reg_ngas reg_kero reg_prop using Final_Output\tab_OldRegs_Update.tex, label replace order(new_lncfuelself new_inc_* new_rac_* new_own new_rural new_reg_* new_vin_*) keep(new_lncfuelself new_inc_* new_rac_* new_own new_rural new_reg_* new_vin_*) noconstant b(3) se(3) fragment mtitle("Heat pump" "Electric" "Natural gas" "Heating oil" "Propane") substitute($ "\\$")


* NEW HOMES: CORRELATES OF HEATING FUEL SHARES
eststo clear
local heatlist "hp elec ngas kero prop"
foreach h of local heatlist { 
	replace lncself = lnc`h'
	replace lncfuel = (lnca*(shp + selec + sngas + skero + sprop) - s`h'*lnc`h')/(shp + selec + sngas + skero + sprop - s`h')
	replace lncfuelself = lncfuel - lncself
	replace new_lncfuelself = new*lncfuelself
	eststo: reg `h' lncfuelself inc_* rac_* own rural reg_* if vintage>2000 [pw=nweight], robust
	estimates store new_`h'
}
esttab new_hp new_elec new_ngas new_kero new_prop using Final_Output\tab_NewRegs_Update.tex, label replace order(lncfuelself inc_* rac_* own rural reg_*) keep(lncfuelself inc_* rac_* own rural reg_*) noconstant b(3) se(3) fragment mtitle("Heat pump" "Electric" "Natural gas" "Heating oil" "Propane") substitute($ "\\$")


clear
exit






